package com.by.job;

import com.by.service.SetmealService;
import com.by.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ClearImgJob {

    @Autowired
    private SetmealService setmealService;

    public void clearImg() {
        //2.1查找垃圾图片
        List<String> picNameList = setmealService.selectSetmeal();

        //2.2删除垃圾图片
        for (String picName : picNameList) {
            //删除七牛云云端图片
            QiniuUtils.deleteFileFromQiniu(picName);
            //删除数据库中的图片
            setmealService.deleteSetmealPicByPicName(picName);
            System.out.println(new Date() + "定时清理垃圾图片" + picName);
        }
    }

}
